package com.ldx.java_chatroom.mapper;

import com.ldx.java_chatroom.model.Message;
import com.ldx.java_chatroom.model.item.MessageItem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageMapper {
    @Select("select content from message where sessionId = #{sessonId} " +
            "order by postTime desc limit 1")
    String getLastMessageBySessionId(int sessionId);
    @Select("select messageId,fromId,userName as fromName,sessionId,content from user,message" +
            " where user.userId = message.fromId and message.sessionId = #{sessionId} " +
            "order by postTime desc limit 100")
     List<Message> getMessagesBySessionId(int sessionId);
    @Insert("insert into message values (null,#{fromId},#{sessionId},#{content},now())")
    void add(MessageItem messageItem);
}
